#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

int main()
{
  umask(0);
  //int fd = open("log.txt", O_CREAT | O_WRONLY | O_TRUNC, 0666); //建, 写, 清
  //int fd = open("log.txt", O_CREAT | O_WRONLY | O_APPEND, 0666); //建, 写, 加
  int fd = open("log.txt", O_RDONLY); //建, 写, 加
  if(fd < 0)
  {
    return 1;
  }

  while(1)
  {
    char buff[64];
    int n = read(fd, buff, sizeof(buff) - 1);
    if(n > 0) 
    {
      buff[n] = 0;
      printf("%s", buff);
    }
    else 
    {
      break;
    }
  }

  //const char *msg = "hello bit\n";
  //int cnt = 5;
  //while(cnt--)
  //{
  //  write(fd, msg, strlen(msg));
  //}

  //close(fd);
  return 0;
}
